/*==============================================================================
项目: 医疗卫生服务能力综合评价 - 面板数据熵权TOPSIS分析
作者: Stata分析系统
日期: 2024-11-07
数据: 7个地区，2020-2022年，9个评价指标
方法: 熵权法 + TOPSIS法 + 面板数据分析
==============================================================================*/

clear all
set more off
set scheme s2color

* 设置工作目录和日志
cd "/Users/mac/git/stata"
capture log close
log using "output/cases/case10_panel_analysis.log", replace text

display "================================================================================"
display "医疗卫生服务能力综合评价 - 面板数据熵权TOPSIS分析"
display "================================================================================"
display ""

/*------------------------------------------------------------------------------
第一部分：数据导入与预处理
------------------------------------------------------------------------------*/

display "第一部分：数据导入与预处理"
display "--------------------------------------------------------------------------------"

* 导入数据
import delimited "data/cases/healthcare_panel.csv", clear encoding(utf8)

* 查看数据结构
describe
list in 1/10, clean noobs

* 设置面板数据结构
encode region, gen(region_code)
xtset region_code year

display ""
display "面板数据结构:"
xtdescribe

* 定义指标列表
local indicators "hospitals beds doctors nurses outpatient_cost inpatient_cost bed_utilization total_visits discharges"
local n_indicators = 9

* 定义正向和负向指标
local positive_indicators "hospitals beds doctors nurses bed_utilization total_visits discharges"
local negative_indicators "outpatient_cost inpatient_cost"

display ""
display "评价指标体系:"
display "  正向指标(7个): 医院个数、床位数量、医师人数、护士人数、病床使用率、总诊疗人次、出院人次"
display "  负向指标(2个): 门诊人均费用、住院人均费用"
display ""

/*------------------------------------------------------------------------------
第二部分：描述性统计与数据质量检查
------------------------------------------------------------------------------*/

display "第二部分：描述性统计与数据质量检查"
display "--------------------------------------------------------------------------------"

* 基本统计
summarize `indicators', detail

* 缺失值检查
display ""
display "缺失值检查:"
foreach var of local indicators {
    qui count if missing(`var')
    if r(N) > 0 {
        display "  ✗ `var' 有 " r(N) " 个缺失值"
    }
    else {
        display "  ✓ `var' 无缺失值"
    }
}

* 异常值检测（3σ原则）
display ""
display "异常值检测（3σ原则）:"
foreach var of local indicators {
    qui summarize `var'
    local mean = r(mean)
    local sd = r(sd)
    local lower = `mean' - 3*`sd'
    local upper = `mean' + 3*`sd'
    
    qui count if `var' < `lower' | `var' > `upper'
    if r(N) > 0 {
        display "  ! `var' 有 " r(N) " 个异常值"
    }
    else {
        display "  ✓ `var' 无异常值"
    }
}

* 面板数据平衡性检查
display ""
display "面板数据平衡性:"
qui xtdescribe
display "  - 地区数: " r(n)
display "  - 时间跨度: " r(tmin) " - " r(tmax)
display "  - 总观测数: " r(N)

/*------------------------------------------------------------------------------
第三部分：面板数据趋势分析
------------------------------------------------------------------------------*/

display ""
display "第三部分：面板数据趋势分析"
display "--------------------------------------------------------------------------------"

* 计算各年份的平均值
preserve
collapse (mean) `indicators', by(year)
list, clean noobs
restore

* 计算各地区的平均值
preserve
collapse (mean) `indicators', by(region_id region)
list, clean noobs separator(0)
restore

/*------------------------------------------------------------------------------
第四部分：数据标准化（向量归一化）
------------------------------------------------------------------------------*/

display ""
display "第四部分：数据标准化"
display "--------------------------------------------------------------------------------"

* 负向指标转换为正向（取倒数）
foreach var of local negative_indicators {
    qui gen `var'_inv = 1 / `var'
    label variable `var'_inv "`var' (inverse)"
}

* 更新指标列表（负向指标用倒数）
local indicators_norm "hospitals beds doctors nurses outpatient_cost_inv inpatient_cost_inv bed_utilization total_visits discharges"

* 向量归一化
foreach var of local indicators_norm {
    * 计算平方和
    qui egen double `var'_sq_sum = total(`var'^2)
    * 标准化
    qui gen double `var'_norm = `var' / sqrt(`var'_sq_sum)
    drop `var'_sq_sum
}

* 验证标准化
display "标准化验证（每列平方和应为1）:"
foreach var of local indicators_norm {
    qui egen double check_sum = total(`var'_norm^2)
    local sum_val = check_sum[1]
    display "  `var': " %8.6f `sum_val'
    drop check_sum
}

display ""
display "✓ 数据标准化完成"

/*------------------------------------------------------------------------------
第五部分：熵权法计算权重
------------------------------------------------------------------------------*/

display ""
display "第五部分：熵权法计算权重"
display "--------------------------------------------------------------------------------"

local n_obs = _N
local k = 1 / ln(`n_obs')

foreach var of local indicators_norm {
    * 计算比重 p_ij
    qui egen double `var'_sum = total(`var'_norm)
    qui gen double `var'_p = `var'_norm / `var'_sum
    
    * 处理p=0的情况（避免ln(0)）
    qui replace `var'_p = 0.0001 if `var'_p <= 0
    
    * 计算熵值 E_j
    qui gen double `var'_ln = `var'_p * ln(`var'_p)
    qui egen double `var'_e_sum = total(`var'_ln)
    qui gen double `var'_e = -`k' * `var'_e_sum
    
    * 计算差异系数 D_j
    qui gen double `var'_d = 1 - `var'_e
    
    * 清理临时变量
    drop `var'_sum `var'_ln `var'_e_sum
}

* 计算权重
egen double d_sum = rowtotal(*_d)
foreach var of local indicators_norm {
    qui gen double `var'_w = `var'_d / d_sum
}
drop d_sum

* 显示权重结果
display "熵权计算结果:"
display "================================================================================"
display "指标" _col(30) "熵值(E)" _col(45) "差异系数(D)" _col(60) "权重(W)"
display "--------------------------------------------------------------------------------"

local indicator_names "医院个数 床位数量 医师人数 护士人数 门诊费用(逆) 住院费用(逆) 病床使用率 总诊疗人次 出院人次"
local i = 1
foreach var of local indicators_norm {
    local name : word `i' of `indicator_names'
    local e_val = `var'_e[1]
    local d_val = `var'_d[1]
    local w_val = `var'_w[1]
    display "`name'" _col(30) %8.6f `e_val' _col(45) %8.6f `d_val' _col(60) %8.6f `w_val'
    local i = `i' + 1
}
display "================================================================================"

* 验证权重和
egen double weight_sum_check = rowtotal(*_w)
local ws = weight_sum_check[1]
display ""
display "权重和验证: " %8.6f `ws' " (应为1.000000)"
drop weight_sum_check

/*------------------------------------------------------------------------------
第六部分：TOPSIS法计算相对贴近度
------------------------------------------------------------------------------*/

display ""
display "第六部分：TOPSIS法计算相对贴近度"
display "--------------------------------------------------------------------------------"

* 计算加权标准化矩阵
foreach var of local indicators_norm {
    qui gen double `var'_weighted = `var'_norm * `var'_w[1]
}

* 确定正理想解和负理想解
foreach var of local indicators_norm {
    qui egen double `var'_max = max(`var'_weighted)
    qui egen double `var'_min = min(`var'_weighted)
}

* 计算距离
gen double dist_positive = 0
gen double dist_negative = 0

foreach var of local indicators_norm {
    qui replace dist_positive = dist_positive + (`var'_weighted - `var'_max)^2
    qui replace dist_negative = dist_negative + (`var'_weighted - `var'_min)^2
}

qui replace dist_positive = sqrt(dist_positive)
qui replace dist_negative = sqrt(dist_negative)

* 计算相对贴近度
gen double closeness = dist_negative / (dist_positive + dist_negative)

* 计算综合得分（0-100分）
gen double score = closeness * 100

display "✓ TOPSIS计算完成"

/*------------------------------------------------------------------------------
第七部分：面板数据排名与分析
------------------------------------------------------------------------------*/

display ""
display "第七部分：面板数据排名与分析"
display "--------------------------------------------------------------------------------"

* 按年份分别排名
bysort year: egen rank_year = rank(-score)

* 总体排名
egen rank_overall = rank(-score)

* 按地区分组
bysort region_id: egen avg_score = mean(score)
egen rank_region = rank(-avg_score)

* 显示各年份排名
display "各年份综合评价排名:"
display "================================================================================"
forvalues y = 2020/2022 {
    display ""
    display "【`y'年】"
    display "排名" _col(8) "地区" _col(20) "综合得分" _col(35) "相对贴近度"
    display "--------------------------------------------------------------------------------"
    preserve
    keep if year == `y'
    sort rank_year
    list rank_year region score closeness in 1/7, clean noobs separator(0)
    restore
}
display "================================================================================"

* 显示地区平均排名
display ""
display "地区平均表现排名（2020-2022年）:"
display "================================================================================"
display "排名" _col(8) "地区" _col(20) "平均得分" _col(35) "最高分" _col(50) "最低分"
display "--------------------------------------------------------------------------------"
preserve
collapse (mean) avg_score=score (max) max_score=score (min) min_score=score, by(region_id region rank_region)
sort rank_region
list rank_region region avg_score max_score min_score, clean noobs separator(0)
restore
display "================================================================================"

/*------------------------------------------------------------------------------
第八部分：时间趋势分析
------------------------------------------------------------------------------*/

display ""
display "第八部分：时间趋势分析"
display "--------------------------------------------------------------------------------"

* 计算各地区得分变化
display "各地区得分变化趋势:"
display "================================================================================"
display "地区" _col(15) "2020年得分" _col(30) "2021年得分" _col(45) "2022年得分" _col(60) "总变化"
display "--------------------------------------------------------------------------------"

preserve
keep region_id region year score
reshape wide score, i(region_id region) j(year)
gen total_change = score2022 - score2020
list region score2020 score2021 score2022 total_change, clean noobs separator(0)

* 保存变化数据用于后续分析
tempfile changes
save `changes'
restore

* 识别进步最快和退步最快的地区
preserve
use `changes', clear
gsort -total_change
local best_region = region[1]
local best_change = total_change[1]
gsort total_change
local worst_region = region[1]
local worst_change = total_change[1]
restore

display ""
display "关键发现:"
if `best_change' > 0 {
    display "  ✓ 进步最快: `best_region' (得分提升 " %6.2f `best_change' " 分)"
}
else {
    display "  ✓ 表现最稳定: `best_region' (得分变化 " %6.2f `best_change' " 分)"
}
if `worst_change' < 0 {
    display "  ✗ 退步最快: `worst_region' (得分下降 " %6.2f abs(`worst_change') " 分)"
}
else {
    display "  ✗ 进步最慢: `worst_region' (得分变化 " %6.2f `worst_change' " 分)"
}

/*------------------------------------------------------------------------------
第九部分：分组分析
------------------------------------------------------------------------------*/

display ""
display "第九部分：分组分析"
display "--------------------------------------------------------------------------------"

* 按得分分组
gen performance_group = "优秀" if score >= 60
replace performance_group = "良好" if score >= 50 & score < 60
replace performance_group = "中等" if score >= 40 & score < 50
replace performance_group = "较差" if score < 40

* 统计各组数量
display "绩效分组统计:"
tab performance_group year, row

* 各组平均指标
display ""
display "各绩效组平均指标值:"
preserve
collapse (mean) `indicators', by(performance_group)
list, clean noobs separator(0)
restore

/*------------------------------------------------------------------------------
第十部分：相关性分析
------------------------------------------------------------------------------*/

display ""
display "第十部分：相关性分析"
display "--------------------------------------------------------------------------------"

display "综合得分与各指标的相关系数:"
foreach var of local indicators {
    qui correlate score `var'
    local corr = r(rho)
    display "  `var': " %6.4f `corr'
}

/*------------------------------------------------------------------------------
第十一部分：可视化分析
------------------------------------------------------------------------------*/

display ""
display "第十一部分：可视化分析"
display "--------------------------------------------------------------------------------"

capture mkdir "output/cases/figures"

* 1. 各地区得分时间趋势图
display "生成图表1: 各地区得分时间趋势图..."
xtline score, overlay ///
    title("医疗卫生服务能力综合评价得分趋势", size(medium)) ///
    subtitle("2020-2022年", size(small)) ///
    ytitle("综合得分") ///
    xtitle("年份") ///
    ylabel(0(10)100, labsize(small)) ///
    legend(size(vsmall) position(3) cols(1)) ///
    scheme(s2color) ///
    graphregion(color(white))
graph export "output/cases/figures/panel_score_trend.png", as(png) width(1200) replace

* 2. 各年份得分对比箱线图
display "生成图表2: 各年份得分对比箱线图..."
graph box score, over(year) ///
    title("各年份综合得分分布", size(medium)) ///
    ytitle("综合得分") ///
    ylabel(0(10)100, labsize(small)) ///
    box(1, fcolor(navy%70)) ///
    marker(1, mcolor(red) msize(small)) ///
    scheme(s2color) ///
    graphregion(color(white)) ///
    note("注: 红点表示异常值", size(vsmall))
graph export "output/cases/figures/panel_score_boxplot.png", as(png) width(1200) replace

* 3. 地区平均得分排名图
display "生成图表3: 地区平均得分排名图..."
preserve
collapse (mean) avg_score=score, by(region_id region)
gsort -avg_score
gen rank = _n
graph bar avg_score, over(region, sort(rank) label(labsize(small))) ///
    title("各地区平均综合得分排名", size(medium)) ///
    subtitle("2020-2022年平均", size(small)) ///
    ytitle("平均综合得分") ///
    ylabel(0(10)100, labsize(small)) ///
    bar(1, fcolor(dkgreen%70) lcolor(dkgreen)) ///
    scheme(s2color) ///
    graphregion(color(white))
graph export "output/cases/figures/panel_region_ranking.png", as(png) width(1200) replace
restore

* 4. 得分变化热力图（使用散点图模拟）
display "生成图表4: 地区-年份得分热力图..."
separate score, by(year)
graph twoway ///
    (scatter region_id year if year==2020, msize(huge) mcolor(red%30) mlabel(score2020) mlabsize(tiny)) ///
    (scatter region_id year if year==2021, msize(huge) mcolor(blue%30) mlabel(score2021) mlabsize(tiny)) ///
    (scatter region_id year if year==2022, msize(huge) mcolor(green%30) mlabel(score2022) mlabsize(tiny)), ///
    title("地区-年份综合得分分布", size(medium)) ///
    ytitle("地区ID") ///
    xtitle("年份") ///
    ylabel(1(1)7, labsize(small)) ///
    xlabel(2020(1)2022, labsize(small)) ///
    legend(order(1 "2020年" 2 "2021年" 3 "2022年") size(small) position(3)) ///
    scheme(s2color) ///
    graphregion(color(white))
graph export "output/cases/figures/panel_heatmap.png", as(png) width(1200) replace
drop score2020 score2021 score2022

* 5. 指标权重分布图
display "生成图表5: 指标权重分布图..."

* 先保存权重值到locals
local w1 = hospitals_w[1]
local w2 = beds_w[1]
local w3 = doctors_w[1]
local w4 = nurses_w[1]
local w5 = outpatient_cost_inv_w[1]
local w6 = inpatient_cost_inv_w[1]
local w7 = bed_utilization_w[1]
local w8 = total_visits_w[1]
local w9 = discharges_w[1]

preserve
clear
set obs 9
gen str30 indicator = ""
gen weight = .

local indicator_names "医院个数 床位数量 医师人数 护士人数 门诊费用(逆) 住院费用(逆) 病床使用率 总诊疗人次 出院人次"

qui replace indicator = "医院个数" in 1
qui replace weight = `w1' in 1
qui replace indicator = "床位数量" in 2
qui replace weight = `w2' in 2
qui replace indicator = "医师人数" in 3
qui replace weight = `w3' in 3
qui replace indicator = "护士人数" in 4
qui replace weight = `w4' in 4
qui replace indicator = "门诊费用(逆)" in 5
qui replace weight = `w5' in 5
qui replace indicator = "住院费用(逆)" in 6
qui replace weight = `w6' in 6
qui replace indicator = "病床使用率" in 7
qui replace weight = `w7' in 7
qui replace indicator = "总诊疗人次" in 8
qui replace weight = `w8' in 8
qui replace indicator = "出院人次" in 9
qui replace weight = `w9' in 9

egen rank = rank(-weight)
graph bar weight, over(indicator, sort(rank) label(labsize(vsmall) angle(45))) ///
    title("评价指标权重分布", size(medium)) ///
    subtitle("基于熵权法", size(small)) ///
    ytitle("权重值") ///
    ylabel(0(0.05)0.25, labsize(small) format(%4.2f)) ///
    bar(1, fcolor(maroon%70) lcolor(maroon)) ///
    scheme(s2color) ///
    graphregion(color(white)) ///
    note("注: 权重越大表示该指标差异越大，对评价影响越大", size(vsmall))
graph export "output/cases/figures/panel_indicator_weights.png", as(png) width(1200) replace
restore

* 6. 2022年前3名地区指标对比图
display "生成图表6: 2022年前3名地区指标对比图..."
preserve
keep if year == 2022
gsort -score
keep in 1/3
keep region hospitals beds doctors nurses bed_utilization total_visits discharges

* 标准化指标用于对比（0-100）
foreach var in hospitals beds doctors nurses bed_utilization total_visits discharges {
    qui egen `var'_min = min(`var')
    qui egen `var'_max = max(`var')
    qui gen `var'_std = (`var' - `var'_min) / (`var'_max - `var'_min) * 100
    drop `var' `var'_min `var'_max
}

graph bar hospitals_std beds_std doctors_std nurses_std bed_utilization_std total_visits_std discharges_std, ///
    over(region, label(labsize(small))) ///
    title("2022年前3名地区主要指标对比", size(medium)) ///
    subtitle("标准化得分(0-100)", size(small)) ///
    ytitle("标准化得分") ///
    ylabel(0(20)100, labsize(small)) ///
    legend(order(1 "医院个数" 2 "床位数量" 3 "医师人数" 4 "护士人数" ///
                 5 "病床使用率" 6 "总诊疗人次" 7 "出院人次") ///
           size(vsmall) position(3) cols(1)) ///
    scheme(s2color) ///
    graphregion(color(white))
graph export "output/cases/figures/panel_top3_comparison.png", as(png) width(1200) replace
restore

display ""
display "✓ 所有图表已生成"

/*------------------------------------------------------------------------------
第十二部分：保存结果
------------------------------------------------------------------------------*/

display ""
display "第十二部分：保存结果"
display "--------------------------------------------------------------------------------"

* 保存完整结果
preserve
keep region_id region year score closeness rank_year rank_overall performance_group ///
     dist_positive dist_negative
order region_id region year score closeness rank_year rank_overall performance_group
sort year rank_year
export delimited using "output/cases/panel_evaluation_results.csv", replace
display "✓ 完整结果已保存: output/cases/panel_evaluation_results.csv"
restore

* 保存权重信息
preserve
clear
set obs 9
gen str30 indicator = ""
gen str30 indicator_cn = ""
gen weight = .
gen entropy = .
gen diff_coef = .

local indicator_names "医院个数 床位数量 医师人数 护士人数 门诊费用(逆) 住院费用(逆) 病床使用率 总诊疗人次 出院人次"
local indicator_en "hospitals beds doctors nurses outpatient_cost_inv inpatient_cost_inv bed_utilization total_visits discharges"

* 手动填充数据
qui replace indicator = "hospitals" in 1
qui replace indicator_cn = "医院个数" in 1
qui replace weight = `w1' in 1

qui replace indicator = "beds" in 2
qui replace indicator_cn = "床位数量" in 2
qui replace weight = `w2' in 2

qui replace indicator = "doctors" in 3
qui replace indicator_cn = "医师人数" in 3
qui replace weight = `w3' in 3

qui replace indicator = "nurses" in 4
qui replace indicator_cn = "护士人数" in 4
qui replace weight = `w4' in 4

qui replace indicator = "outpatient_cost_inv" in 5
qui replace indicator_cn = "门诊费用(逆)" in 5
qui replace weight = `w5' in 5

qui replace indicator = "inpatient_cost_inv" in 6
qui replace indicator_cn = "住院费用(逆)" in 6
qui replace weight = `w6' in 6

qui replace indicator = "bed_utilization" in 7
qui replace indicator_cn = "病床使用率" in 7
qui replace weight = `w7' in 7

qui replace indicator = "total_visits" in 8
qui replace indicator_cn = "总诊疗人次" in 8
qui replace weight = `w8' in 8

qui replace indicator = "discharges" in 9
qui replace indicator_cn = "出院人次" in 9
qui replace weight = `w9' in 9

order indicator indicator_cn weight
export delimited using "output/cases/panel_indicator_weights.csv", replace
display "✓ 指标权重已保存: output/cases/panel_indicator_weights.csv"
restore

* 保存年度汇总
preserve
collapse (mean) avg_score=score (sd) sd_score=score (min) min_score=score (max) max_score=score, by(year)
export delimited using "output/cases/panel_yearly_summary.csv", replace
display "✓ 年度汇总已保存: output/cases/panel_yearly_summary.csv"
restore

* 保存地区汇总
preserve
collapse (mean) avg_score=score (sd) sd_score=score (min) min_score=score (max) max_score=score, by(region_id region)
gsort -avg_score
gen rank = _n
export delimited using "output/cases/panel_region_summary.csv", replace
display "✓ 地区汇总已保存: output/cases/panel_region_summary.csv"
restore

/*------------------------------------------------------------------------------
第十三部分：详细分析结论
------------------------------------------------------------------------------*/

display ""
display "================================================================================"
display "第十三部分：详细分析结论"
display "================================================================================"
display ""

* 1. 总体评价
display "【一、总体评价】"
display "--------------------------------------------------------------------------------"
qui summarize score
local mean_score = r(mean)
local sd_score = r(sd)
local min_score = r(min)
local max_score = r(max)

display "  1. 综合得分概况:"
display "     - 平均得分: " %6.2f `mean_score' " 分"
display "     - 标准差: " %6.2f `sd_score' " 分"
display "     - 最高分: " %6.2f `max_score' " 分"
display "     - 最低分: " %6.2f `min_score' " 分"
display "     - 得分区间: " %6.2f `max_score' - `min_score' " 分"
display ""

* 2. 时间趋势
display "【二、时间趋势分析】"
display "--------------------------------------------------------------------------------"
preserve
collapse (mean) avg_score=score, by(year)
list year avg_score, clean noobs
local score_2020 = avg_score[1]
local score_2022 = avg_score[3]
local change = `score_2022' - `score_2020'
restore

display ""
display "  2. 年度变化:"
display "     - 2020年平均得分: " %6.2f `score_2020' " 分"
display "     - 2022年平均得分: " %6.2f `score_2022' " 分"
if `change' > 0 {
    display "     - 总体趋势: ↑ 上升 " %6.2f `change' " 分 (提升 " %5.2f (`change'/`score_2020'*100) "%)"
}
else {
    display "     - 总体趋势: ↓ 下降 " %6.2f abs(`change') " 分 (下降 " %5.2f (abs(`change')/`score_2020'*100) "%)"
}
display ""

* 3. 地区差异
display "【三、地区差异分析】"
display "--------------------------------------------------------------------------------"
preserve
collapse (mean) avg_score=score, by(region_id region)
gsort -avg_score
local top_region = region[1]
local top_score = avg_score[1]
local bottom_region = region[7]
local bottom_score = avg_score[7]
local gap = `top_score' - `bottom_score'
restore

display "  3. 地区表现:"
display "     - 最佳地区: `top_region' (平均 " %6.2f `top_score' " 分)"
display "     - 最差地区: `bottom_region' (平均 " %6.2f `bottom_score' " 分)"
display "     - 地区差距: " %6.2f `gap' " 分"
display ""

* 4. 关键指标
display "【四、关键指标识别】"
display "--------------------------------------------------------------------------------"
display "  4. 权重最高的前3个指标:"

* 创建权重列表用于排序
preserve
clear
set obs 9
gen str30 indicator = ""
gen weight = .

qui replace indicator = "医院个数" in 1
qui replace weight = `w1' in 1
qui replace indicator = "床位数量" in 2
qui replace weight = `w2' in 2
qui replace indicator = "医师人数" in 3
qui replace weight = `w3' in 3
qui replace indicator = "护士人数" in 4
qui replace weight = `w4' in 4
qui replace indicator = "门诊费用(逆)" in 5
qui replace weight = `w5' in 5
qui replace indicator = "住院费用(逆)" in 6
qui replace weight = `w6' in 6
qui replace indicator = "病床使用率" in 7
qui replace weight = `w7' in 7
qui replace indicator = "总诊疗人次" in 8
qui replace weight = `w8' in 8
qui replace indicator = "出院人次" in 9
qui replace weight = `w9' in 9

gsort -weight
forvalues i = 1/3 {
    local ind = indicator[`i']
    local wt = weight[`i']
    display "     第`i'位: `ind' (权重 " %6.4f `wt' ")"
}
restore
display ""

* 5. 管理建议
display "【五、管理建议】"
display "--------------------------------------------------------------------------------"
display "  5.1 对于高分地区:"
display "     ✓ 保持优势，继续提升服务质量"
display "     ✓ 发挥示范作用，分享成功经验"
display "     ✓ 关注薄弱环节，实现全面发展"
display ""
display "  5.2 对于低分地区:"
display "     ✓ 加大投入，补齐基础设施短板"
display "     ✓ 优化资源配置，提高使用效率"
display "     ✓ 学习先进经验，缩小地区差距"
display ""
display "  5.3 对于所有地区:"
display "     ✓ 重点关注权重较高的指标"
display "     ✓ 控制医疗费用，减轻患者负担"
display "     ✓ 提高病床使用率，优化资源利用"
display ""

* 6. 方法说明
display "【六、方法说明】"
display "--------------------------------------------------------------------------------"
display "  6.1 熵权法:"
display "     - 客观赋权方法，基于数据离散程度"
display "     - 差异越大的指标权重越高"
display "     - 避免主观因素影响"
display ""
display "  6.2 TOPSIS法:"
display "     - 逼近理想解排序法"
display "     - 同时考虑与正理想解和负理想解的距离"
display "     - 综合评价更加全面"
display ""
display "  6.3 面板数据分析:"
display "     - 结合时间序列和截面数据"
display "     - 可以观察动态变化趋势"
display "     - 提供更丰富的分析视角"
display ""

display "================================================================================"
display "分析完成！所有结果已保存。"
display "================================================================================"
display ""
display "输出文件:"
display "  - 完整结果: output/cases/panel_evaluation_results.csv"
display "  - 指标权重: output/cases/panel_indicator_weights.csv"
display "  - 年度汇总: output/cases/panel_yearly_summary.csv"
display "  - 地区汇总: output/cases/panel_region_summary.csv"
display "  - 图表文件: output/cases/figures/*.png (共6张)"
display "  - 分析日志: output/cases/case10_panel_analysis.log"
display ""

log close

